package com.region.http.client.common;

import com.region.http.client.model.RequestHeader;

/**
 * The request header parameter context holder
 *
 * @author liujieyu
 * @date 2023/6/10 17:14
 * @desciption
 */
public class RegionContextHolder {

    private static ThreadLocal<RequestHeader> threadLocal = new ThreadLocal<RequestHeader>(){
        @Override
        protected RequestHeader initialValue() {
            return null;
        }
    };

    public static void setHeader(String key, String value) {
        if (threadLocal.get() == null) {
            threadLocal.set(new RequestHeader());
        }
        threadLocal.get().set(key, value);
    }

    public static RequestHeader getHeader() {
        return threadLocal.get();
    }

    public static void remove() {
        threadLocal.remove();
    }

    public static void removeKey(String key) {
        threadLocal.get().remove(key);
    }

}
